package com.example.controller;

import com.example.entity.Category;
import com.example.req.CategorySaveReq;
import com.example.req.EbookSaveReq;
import com.example.service.CategoryService;
import com.example.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


@RestController
public class CategoryController {

    @Autowired
    CategoryService categoryService;
    
    @GetMapping("/categoryList")
    public Result findCategory(){
        return Result.success(categoryService.findCategory());
    }

    @PostMapping("/category")
    public Result saveCategory(@RequestBody @Valid CategorySaveReq req) {
        categoryService.saveCategory(req);
        return Result.success();
    }

    @DeleteMapping("/category/{id}")
    public Result deleteCategory(@PathVariable("id") Long id){
        categoryService.deleteCategory(id);
        return Result.success();
    }

}
